/**
 * Created by yvdedu.com on 2016/11/4.
 */
!function(){
    var page=1;
    var search=location.search.replace(/\?search=([^#^&]*)/,"$1")
    console.log(search);
    $(function(){
        $(window).scroll(function () {
            if($(window).height() + $(window).scrollTop()>=document.scrollingElement.scrollHeight&&$(window).scrollTop()>0){
                var panels=$(".searchContent .ArticlePanel");
                if(panels.length!=0&&panels.length%30==0){
                    $.post("/getSearch",{page:++page,search:search},function(o){
                        if(o){
                            set(JSON.parse(o));
                        }
                    })
                }

            }
        });
    });
    var model=$(".ArticlePanel.scrollbar.model");
    function setArticle(temp){
        var time=new Date(temp.createTime).toLocaleString();
        var tempCare=model.clone();
        tempCare.find(".authorPhoto").attr("src",temp.user.photo?temp.user.photo:"photo/0.png")
        tempCare.find(".author").attr("href","user"+temp.user.id);
        tempCare.find(".author").text(temp.user.nickName?temp.user.nickName:temp.user.name);
        tempCare.find(".createTime").text("发表时间："+time);
        tempCare.find(".ck").text("查看"+temp.click);
        tempCare.find(".title.at").attr("href","Article"+temp.id);
        tempCare.find(".title.at").text(temp.name);
        if(tempCare.find("a")){
            tempCare.find("a").attr("href","/noUseArticle?id="+temp.id);
        }
        tempCare.css("display","block");
        return tempCare;
    }
    function set(js){
        for(var i=0;i<js.length;++i){
            $(".content.new").append(setArticle(js[i]));
        }
    }
}();


